package com.macasa.panel.entity.impl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.IRole;

@Entity
@Table(name = "role")
@SequenceGenerator(name = "Role_SEQ", sequenceName = "RoleIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class Role extends AbstractModel<Integer> implements IRole {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= -2395127192839347778L;

	@Id
	@Column(name = "id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "Role_SEQ")
	private Integer				id;

	@Column(name = "name", nullable = false)
	private String				name;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Role)) {
			return false;
		}

		final Role other = CastHelpers.cast(obj, Role.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.name, other.name);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.name);
	}
}
